import { CHANGE_INPUT, ADD_ITEM, DEL_ITEM, GET_LIST, GET_MY_LIST } from '../actionTypes'
import axios from 'axios'

export const changeInputAction = (value) => ({
    type:CHANGE_INPUT,
    value
})

export const addItemAction = () => ({
    type:ADD_ITEM
})

export const delItemAction = (index) => ({
    type:DEL_ITEM,
    index
})

/**
 *  ({}) 返回对象
 *  {}   返回函数
 */
export const getListAction = (data) => ({
    type:GET_LIST,
    data
})

export const getTodoList = () => {
    return (dispatch) => {
        axios.get('http://localhost:3000/app/newApp.json?currentPageNumber=1&pageSize=4').then((res)=>{
       // axios.get('https://www.easy-mock.com/mock/5cfcce489dc7c36bd6da2c99/xiaojiejie/getList').then((res)=>{
            const data = res.data
            console.log(data.page.list)

            const lineData = data.page.list;
            const num = [];
            lineData.forEach(item => {
                num.push(item.name + ": " + item.picname)
            })

            const action = getListAction(num)
            dispatch(action)
        })
    }
}

export const getMyListAction = ()=>({
    type:GET_MY_LIST
})